package com.xiaozhengkeji.starbootserver.bus.services;

import com.google.gson.Gson;
import com.xiaozhengkeji.starbootserver.base.entitys.SysUserEntity;
import com.xiaozhengkeji.starbootserver.base.services.PermissionTableEntityService;
import com.xiaozhengkeji.starbootserver.base.services.RoleTableEntityService;
import com.xiaozhengkeji.starbootserver.base.services.SysUserEntityService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;

/**
 * 系统用户相关服务
 */
@Service("SystemUserService")
public class SystemUserService {
    SysUserEntityService sysUserEntityService;
    RoleTableEntityService roleTableEntityService;
    PermissionTableEntityService permissionTableEntityService;

    /**
     * 创建系统用户
     */
    public Boolean createSystemUser(String userName, String password, String mailbox) {
        //TODO
        List<String> userRole = new LinkedList<>();
        userRole.add("user-def");
        List<String> userPermission = new LinkedList<>();
        userPermission.add("user:def");
        SysUserEntity sysUserEntity = new SysUserEntity();
        sysUserEntity.setUsername(userName);
        sysUserEntity.setPassword(password);
        sysUserEntity.setMailbox(mailbox);
        sysUserEntity.setPhone(10000000000L);
        sysUserEntity.setRole(new Gson().toJson(userRole));
        sysUserEntity.setPermission(new Gson().toJson(userPermission));
        sysUserEntity.setStatus(1);
        sysUserEntity.setCreationTime(LocalDateTime.now());
        sysUserEntity.setRemark("用户备注");
        return sysUserEntityService.insert(sysUserEntity) > 0;
    }


}
